package site.shenjie.usage.ribbon.otherapi.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 沈杰
 * 2020-7-24 15:02:18
 */
@RestController
public class TestController {
    @Autowired
    private LoadBalancerClient loadBalancer;

    @RequestMapping("/index")
    public String index() {
        ServiceInstance instance = loadBalancer.choose("eureka-client-user-service");
        System.out.println(JSONObject.toJSONString(instance));
        return "<h1>Welcome to test controller!</h1>";
    }
}
